<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>舆情分析系统 - 测试页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        .test-section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #e8e8e8;
            border-radius: 6px;
        }
        .test-section h3 {
            color: #1890ff;
            margin-top: 0;
        }
        .test-result {
            padding: 10px;
            margin: 10px 0;
            border-radius: 4px;
            font-family: monospace;
        }
        .success {
            background: #f6ffed;
            border: 1px solid #b7eb8f;
            color: #52c41a;
        }
        .error {
            background: #fff2f0;
            border: 1px solid #ffccc7;
            color: #ff4d4f;
        }
        .info {
            background: #e6f7ff;
            border: 1px solid #91d5ff;
            color: #1890ff;
        }
        .btn {
            background: #1890ff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            margin: 5px;
        }
        .btn:hover {
            background: #40a9ff;
        }
        .btn:disabled {
            background: #d9d9d9;
            cursor: not-allowed;
        }
        .chart-container {
            height: 300px;
            margin: 20px 0;
            border: 1px solid #e8e8e8;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>舆情分析系统 - 前端功能测试</h1>
        
        <div class="test-section">
            <h3>1. 依赖库测试</h3>
            <button class="btn" onclick="testDependencies()">测试依赖库</button>
            <div id="dependencies-result"></div>
        </div>
        
        <div class="test-section">
            <h3>2. API服务测试</h3>
            <button class="btn" onclick="testAPI()">测试API服务</button>
            <div id="api-result"></div>
        </div>
        
        <div class="test-section">
            <h3>3. ECharts图表测试</h3>
            <button class="btn" onclick="testECharts()">测试图表</button>
            <div id="echarts-result"></div>
            <div id="test-chart" class="chart-container"></div>
        </div>
        
        <div class="test-section">
            <h3>4. Vue.js测试</h3>
            <button class="btn" onclick="testVue()">测试Vue</button>
            <div id="vue-result"></div>
            <div id="vue-test">
                <p>Vue测试: {{ message }}</p>
                <button class="btn" @click="changeMessage">改变消息</button>
            </div>
        </div>
        
        <div class="test-section">
            <h3>5. 页面跳转测试</h3>
            <button class="btn" onclick="window.location.href='pages/console.html'">跳转到首页</button>
            <div class="info test-result">
                点击按钮跳转到舆情分析系统首页
            </div>
        </div>
    </div>

    <!-- 引入依赖 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script src="lib/echarts/echarts.min.js"></script>
    <script src="lib/layui/layui.js"></script>
    <script src="js/api.js"></script>
    
    <script>
        // 测试依赖库
        function testDependencies() {
            const result = document.getElementById('dependencies-result');
            let html = '';
            
            try {
                // 测试Vue
                if (typeof Vue !== 'undefined') {
                    html += '<div class="success test-result">✓ Vue.js 加载成功</div>';
                } else {
                    html += '<div class="error test-result">✗ Vue.js 加载失败</div>';
                }
                
                // 测试Axios
                if (typeof axios !== 'undefined') {
                    html += '<div class="success test-result">✓ Axios 加载成功</div>';
                } else {
                    html += '<div class="error test-result">✗ Axios 加载失败</div>';
                }
                
                // 测试ECharts
                if (typeof echarts !== 'undefined') {
                    html += '<div class="success test-result">✓ ECharts 加载成功</div>';
                } else {
                    html += '<div class="error test-result">✗ ECharts 加载失败</div>';
                }
                
                // 测试Layui
                if (typeof layui !== 'undefined') {
                    html += '<div class="success test-result">✓ Layui 加载成功</div>';
                } else {
                    html += '<div class="error test-result">✗ Layui 加载失败</div>';
                }
                
                // 测试API服务
                if (typeof API !== 'undefined') {
                    html += '<div class="success test-result">✓ API服务 加载成功</div>';
                } else {
                    html += '<div class="error test-result">✗ API服务 加载失败</div>';
                }
                
            } catch (error) {
                html += `<div class="error test-result">测试过程中发生错误: ${error.message}</div>`;
            }
            
            result.innerHTML = html;
        }
        
        // 测试API服务
        async function testAPI() {
            const result = document.getElementById('api-result');
            result.innerHTML = '<div class="info test-result">正在测试API服务...</div>';
            
            try {
                // 测试API对象是否存在
                if (typeof API === 'undefined') {
                    result.innerHTML = '<div class="error test-result">✗ API服务未加载</div>';
                    return;
                }
                
                // 测试API方法
                const apiMethods = [
                    'dashboard.getStats',
                    'dashboard.getTrendData',
                    'dashboard.getSentimentData',
                    'opinion.getHotWords',
                    'aiModel.getModels'
                ];
                
                let html = '<div class="success test-result">✓ API服务对象创建成功</div>';
                
                for (const method of apiMethods) {
                    const parts = method.split('.');
                    const obj = API[parts[0]];
                    const func = obj[parts[1]];
                    
                    if (typeof func === 'function') {
                        html += `<div class="success test-result">✓ ${method} 方法可用</div>`;
                    } else {
                        html += `<div class="error test-result">✗ ${method} 方法不可用</div>`;
                    }
                }
                
                // 测试工具函数
                if (typeof APIUtils !== 'undefined') {
                    html += '<div class="success test-result">✓ APIUtils 工具函数可用</div>';
                    
                    // 测试格式化函数
                    const testNumber = APIUtils.formatNumber(1234567);
                    html += `<div class="info test-result">数字格式化测试: 1234567 → ${testNumber}</div>`;
                } else {
                    html += '<div class="error test-result">✗ APIUtils 工具函数不可用</div>';
                }
                
                result.innerHTML = html;
                
            } catch (error) {
                result.innerHTML = `<div class="error test-result">API测试失败: ${error.message}</div>`;
            }
        }
        
        // 测试ECharts
        function testECharts() {
            const result = document.getElementById('echarts-result');
            const chartContainer = document.getElementById('test-chart');
            
            try {
                if (typeof echarts === 'undefined') {
                    result.innerHTML = '<div class="error test-result">✗ ECharts 未加载</div>';
                    return;
                }
                
                // 创建测试图表
                const chart = echarts.init(chartContainer);
                const option = {
                    title: {
                        text: 'ECharts 测试图表',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        data: [820, 932, 901, 934, 1290, 1330, 1320],
                        type: 'line',
                        smooth: true
                    }]
                };
                
                chart.setOption(option);
                result.innerHTML = '<div class="success test-result">✓ ECharts 图表创建成功</div>';
                
            } catch (error) {
                result.innerHTML = `<div class="error test-result">ECharts测试失败: ${error.message}</div>`;
            }
        }
        
        // 测试Vue.js
        function testVue() {
            const result = document.getElementById('vue-result');
            
            try {
                if (typeof Vue === 'undefined') {
                    result.innerHTML = '<div class="error test-result">✗ Vue.js 未加载</div>';
                    return;
                }
                
                // 创建Vue实例
                new Vue({
                    el: '#vue-test',
                    data: {
                        message: 'Hello Vue!'
                    },
                    methods: {
                        changeMessage() {
                            this.message = 'Vue.js 工作正常! ' + new Date().toLocaleTimeString();
                        }
                    }
                });
                
                result.innerHTML = '<div class="success test-result">✓ Vue.js 实例创建成功</div>';
                
            } catch (error) {
                result.innerHTML = `<div class="error test-result">Vue测试失败: ${error.message}</div>`;
            }
        }
        
        // 页面加载完成后自动运行基础测试
        window.addEventListener('load', function() {
            setTimeout(() => {
                testDependencies();
            }, 1000);
        });
    </script>
</body>
</html> 